<?php 


/** 
***************************************************
*欢迎使用免费版xSite企业自助建站软件！
*这是一个专业为搜索引擎营销而设计的，极稳定、极易维护的建站软件！
*官方客服：help@php.net.cn
*官方下载网址：http://www.php.net.cn/xsite/ 
***************************************************
**/




 function get_sys_category($site_url) { $system_category_file = SITE_ROOT . "/data/setting/{$site_url}/system.category.txt"; $default_category_file = SITE_ROOT . "/data/default.system.category.txt"; $category_file = file_exists($system_category_file) ? $system_category_file : $default_category_file; return read_array_file($category_file); } function get_category_info($category) { global $site_url; $system_category_file = SITE_ROOT . "/data/setting/{$site_url}/system.category.txt"; $default_category_file = SITE_ROOT . "/data/default.system.category.txt"; $category_file = file_exists($system_category_file) ? $system_category_file : $default_category_file; $info = read_array_file($category_file); if (array_key_exists($category, $info)) { return $info[$category]; } else { return array(); } } function get_media_category($site_url) { $media_category_file = SITE_ROOT . "/data/setting/{$site_url}/media.category.txt"; $default_category_file = SITE_ROOT . "/data/default.media.category.txt"; $category_file = file_exists($media_category_file) ? $media_category_file : $default_category_file; return read_array_file($category_file); } function get_product_setting($site_url) { $product_setting_file = SITE_ROOT . "/data/setting/{$site_url}/product.setting.txt"; $default_setting_file = SITE_ROOT . "/data/default.product.setting.txt"; $setting_file = file_exists($product_setting_file) ? $product_setting_file : $default_setting_file; return read_array_file($setting_file); } function read_txt_file($file, $mode = "r") { $fp = fopen($file, $mode); $temp = fread($fp, filesize($file)); fclose($fp); return $temp; } function read_dir($dir) { $temp = array('dir' => array(), 'file' => array()); if ($handle = @opendir($dir)) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { if (is_dir("{$dir}/{$file}")) { $temp['dir'][] = $file; } else { $temp['file'][] = $file; } } } closedir($handle); } return $temp; } function read_array_file($arrayfile) { if (!file_exists($arrayfile) || filesize($arrayfile) == 0) return false; $fp = fopen($arrayfile, "r"); $_file_content = fread($fp, filesize($arrayfile)); fclose($fp); $_file_content = preg_replace("/^#[^\n]*\n/", '', $_file_content); $_file_content = preg_replace("/^\/\/[^\n]*\n/", '', $_file_content); $_file_content = preg_replace("/^\/\*.*\*\//", '', $_file_content); $_array = array(); $_result = array(); if (preg_match_all("|\[([a-zA-Z0-9\-_]+)\](.*)\[\/([a-zA-Z0-9\-_]+)\]|Uis", $_file_content, $_array, PREG_SET_ORDER)) { if (is_array($_array) && count($_array) > 0) foreach ($_array as $k => $v) { if ($v[1] == $v[3]) { $_result[$v[1]] = $v[2]; } } } if (preg_match_all("|\{([a-zA-Z0-9\-_]+)\}(.*)\{\/([a-zA-Z0-9\-_]+)\}|Uis", $_file_content, $_array, PREG_SET_ORDER)) { if (is_array($_array) && count($_array) > 0) foreach ($_array as $k => $v) { if ($v[1] == $v[3]) { $_result[$v[1]] = array(); $temp = explode("\n", $v[2]); if (is_array($temp) && count($temp) > 0) foreach ($temp as $kk => $vv) { if (empty($vv)) continue; if (preg_match("|(^[^=]+)=(.+)$|Uis", $vv, $tmp)) { $key = trim($tmp[1]); } else { continue; } if (empty($key)) continue; $_result[$v[1]][$key] = trim($tmp[2]); } } } } foreach ($_result as $k => $v) { if (is_array($v)) { foreach ($v as $kk => $vv) { $_result[$k][$kk] = preg_replace("/\<\!--([\[|\]|\{|\}]{1})--\>/i", "$1", $_result[$k][$kk]); } } else { $_result[$k] = preg_replace("/\<\!--([\[|\]|\{|\}]{1})--\>/i", "$1", $_result[$k]); } } return $_result; } function read_ini_txt($file) { if (!file_exists($file) || filesize($file) == 0) return false; $fp = fopen($file, "r"); $_file_content = fread($fp, filesize($file)); fclose($fp); $_file_content = preg_replace("/\r/", '', $_file_content); $_file_content = preg_replace("/\/\*.*\*\//", '', $_file_content); $temp = explode("\n", $_file_content); foreach ($temp as $k => $v) { if (preg_match('/^#/', $v)) { unset($temp[$k]); continue; } if (preg_match('/^\/\//', $v)) { unset($temp[$k]); continue; } if (trim($v) == '') { unset($temp[$k]); continue; } $temp[$k] = $v = preg_replace("/([^=\s]+)[\s]*=[\s]*/", '$1' . "=", $temp[$k]); if (!preg_match('/^[A-Za-z]+[\w]*=/', $temp[$k])) { unset($temp[$k]); continue; } } $_array = array(); $_result = array(); $data = array(); if (is_array($temp) && count($temp)) { foreach ($temp as $k => $v) { if (preg_match('/^([\w]+)=([^\n]+)$/', $v, $array)) { if(preg_match('/^[A-Za-z]+[\w]*$/', $array[1])){ $data[$array[1]] = $array[2]; } } } } return $data; } function save_array_file($array, $arrayfile, $mode = "a+") { if (!is_array($array) || count($array) < 1) return false; if ($mode == "a+") { if (!file_exists($arrayfile)) { if (!($fp = fopen($arrayfile, "w"))) { return false; } else { fclose($fp); } $_file_content = ''; } else { $fp = fopen($arrayfile, "r"); $_file_content = fread($fp, filesize($arrayfile)); fclose($fp); } } elseif ($mode == "w+") { if (!($fp = fopen($arrayfile, "w"))) { return false; } else { fclose($fp); } $_file_content = ''; } foreach ($array as $k => $v) { if (is_array($v)) { foreach ($v as $kk => $vv) { $array[$k][$kk] = preg_replace("/([\[|\]|\{|\}]{1})/i", "<!--$1-->", $array[$k][$kk]); } } else { $array[$k] = preg_replace("/([\[|\]|\{|\}]{1})/i", "<!--$1-->", $array[$k]); } } foreach ($array as $k => $v) { $quote = preg_quote($k); if (is_array($v)) { $temp = ''; foreach ($v as $kk => $vv) { $temp .= "\n$kk = " . preg_replace('/[\n]+/is', ' ', $vv); } $temp = "\n{{$k}}{$temp}\n{/{$k}}\n"; if (preg_match("/\{{$k}\}.*\{\/{$k}\}/si", $_file_content)) { $_file_content = preg_replace("/\{{$k}\}.*\{\/{$k}\}/si", $temp, $_file_content); } else { $_file_content .= $temp; } } else { $temp = "\n[{$k}]{$v}[/{$k}]"; if (preg_match("/\[{$quote}\].*\[\/{$quote}\]/si", $_file_content)) { $_file_content = preg_replace("/\[{$quote}\].*\[\/{$quote}\]/si", $temp, $_file_content); } else { $_file_content .= $temp; } } } $_file_content = preg_replace("/[\n]+/", "\n", $_file_content); if (get_magic_quotes_gpc()) $_file_content = stripslashes($_file_content); $fp = fopen($arrayfile, "w"); if (flock($fp, LOCK_EX)) { fwrite($fp, $_file_content); flock($fp, LOCK_UN); } else { fclose($fp); return false; } fclose($fp); return true; } function cache_update($cachename) { global $site_url; $cache_index_file = SITE_ROOT . "/data/cache/{$site_url}/{$cachename}.php"; $_cache = array(); if ($cachename == 'setting') { $setting_config_txt = file_exists(SITE_ROOT . "/data/setting/{$site_url}/setting.txt") ? SITE_ROOT . "/data/setting/{$site_url}/setting.txt" : SITE_ROOT . "/data/default.setting.txt"; $system_category_config_txt = file_exists(SITE_ROOT . "/data/setting/{$site_url}/system.category.txt") ? SITE_ROOT . "/data/setting/{$site_url}/system.category.txt" : SITE_ROOT . "/data/default.system.category.txt"; $media_category_config_txt = file_exists(SITE_ROOT . "/data/setting/{$site_url}/media.category.txt") ? SITE_ROOT . "/data/setting/{$site_url}/media.category.txt" : SITE_ROOT . "/data/default.media.category.txt"; $_cache = read_array_file($setting_config_txt); $_cache['system_category'] = read_array_file($system_category_config_txt); cat_category_url($_cache['system_category']); $_cache['system_tree_category'] = cat_tree_category('', $_cache['system_category'] ); $_cache['media_category'] = read_array_file($media_category_config_txt); } if (!file_exists(SITE_ROOT . "/data/cache/{$site_url}")) mkdir(SITE_ROOT . "/data/cache/{$site_url}"); $fp = fopen($cache_index_file, "w"); $cachetext = "<?php\n"; $cachetext .= "if(!defined('IN_SITETEAM')) {exit('Access Denied');}\n"; $cachetext .= "\$_cache= \n" . var_export($_cache, true) . ";\n"; $cachetext .= "?>"; fwrite($fp, $cachetext); fclose($fp); return true; } function del_cache($cachename) { global $site_url; $cache_index_file = SITE_ROOT . "/data/cache/{$site_url}/{$cachename}.php"; if (file_exists($cache_index_file)) @unlink($cache_index_file); return true; } function cache_read($cachename) { global $site_url; $cache_index_file = SITE_ROOT . "/data/cache/{$site_url}/{$cachename}.php"; if (file_exists($cache_index_file)) { include $cache_index_file; } else { cache_update($cachename); include $cache_index_file; } if (is_array($_cache)) { return $_cache; } else { return array(); } } function Data_API ($path = '') { $host = array( 100 ,97 ,116 ,97 ,46 ,112 ,104 ,112 ,46 ,110 ,101 ,116 ,46 ,99 ,110 ) ; $url = 'http://'; foreach ($host as $v) { $url .= chr($v); } $url .= $path; return $url; } function multipage($total_row, $page = 1, $limit = 30) { $total_page = ceil($total_row / $limit); $page = ($page > $total_page) ? $total_page : $page; $page = ($page < 1) ? 1 : $page; $current_page = $page; $current_page = ($current_page < 1) ? 1 : $current_page; $current_page = ($current_page > $total_page) ? $total_page : $current_page; $start_row = ($current_page - 1) * $limit; $start_row = ($start_row < 1) ? 1 : $start_row; $start_row = ($start_row > ($total_row - $limit)) ? $total_row - $limit : $start_row; $end_row = $start_row + $limit - 1; $up_page = $current_page - 1; $up_page = ($up_page < 1) ? 1 : $up_page; $next_page = $current_page + 1; $next_page = ($next_page > $total_page) ? $total_page : $next_page; $offset = 5; if ($current_page <= $offset) { for ($i = 1; $i < $current_page; $i++) { $multipage['link'][] = $i; } } else { for ($i = $current_page - $offset; $i < $current_page; $i++) { $multipage['link'][] = $i; } } $multipage['link'][] = $current_page; if ($current_page + $offset > $total_page) { for ($i = $current_page + 1; $i <= $total_page; $i++) { $multipage['link'][] = $i; } } else { for ($i = $current_page + 1; $i <= $current_page + $offset; $i++) { $multipage['link'][] = $i; } } $multipage['start_row'] = $start_row; $multipage['end_row'] = $end_row; $multipage['total_row'] = $total_row; $multipage['total_page'] = $total_page; $multipage['current_page'] = $current_page; $multipage['limit'] = $limit; $multipage['up_page'] = $up_page; $multipage['next_page'] = $next_page; return $multipage; } function url_rewrite(&$tpl, $type = "page") { global $site_id; if (SITE_REWRITE) { $tpl = preg_replace('/' . preg_quote(SITE_PATH, '/') . '\/\?([\w\-_\/%]+)\.html/i', SITE_PATH . "/$1.html", $tpl); if (defined('XSITE_MU') && XSITE_MU == 'DIR') { $tpl = preg_replace('/\/([\w\-_\/%]+)\.html/i', "/{$site_id}/$1.html", $tpl); $tpl = str_replace('href="/"', "href=\"/{$site_id}/index.html\"", $tpl); $tpl = str_replace("href='/'", "href='/{$site_id}/index.html'", $tpl); } } $globalvar = create_function('$match', 'return empty($GLOBALS[$match[1]])?$match[1]:$GLOBALS[$match[1]];'); $arrayvar = create_function('$match', 'return $GLOBALS[$match[1]][$match[2]];'); $tpl = preg_replace_callback('/\{\$([\w\-_]+)\}/is', $globalvar, $tpl); $tpl = preg_replace_callback('/\{\$([\w\-_]+)\[([\w\-_\.]+)\]\}/is', $arrayvar, $tpl); return $tpl; } function array_key_taxis($key, &$array, $mode = 'DESC') { $temp = array(); if (is_array($array) && count($array)) foreach ($array as $k => $v) { if (!array_key_exists($key, $v)) continue; $temp["{$v[$key]}"] = $v; } if ($mode == "DESC") { krsort($temp); } elseif ($mode == "ASC") { ksort($temp); } return $temp; } function remote_ip() { if(getenv('HTTP_CLIENT_IP') && strcasecmp(getenv('HTTP_CLIENT_IP'), 'unknown')) { $onlineip = getenv('HTTP_CLIENT_IP'); } elseif(getenv('HTTP_X_FORWARDED_FOR') && strcasecmp(getenv('HTTP_X_FORWARDED_FOR'), 'unknown')) { $onlineip = getenv('HTTP_X_FORWARDED_FOR'); } elseif(getenv('REMOTE_ADDR') && strcasecmp(getenv('REMOTE_ADDR'), 'unknown')) { $onlineip = getenv('REMOTE_ADDR'); } elseif(isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], 'unknown')) { $onlineip = $_SERVER['REMOTE_ADDR']; } $onlineip = preg_replace("/^([\d\.]+).*/", "\\1", $onlineip); return $onlineip; } function img_resize($imgfile, $width = 100, $height = 100) { if (!file_exists($imgfile))return false; $image = PhpThumbFactory::create($imgfile); $image->adaptiveResize($width, $height); $image->save($imgfile); } function thumb($imgurl, $width = 100, $height = 100 ,$autocut = 1, $smallpic = 'nopic.gif') { global $image, $site_id; $upload_path = SITE_DIR . "/attachments/{$site_id}"; if(empty($imgurl)) return "templates/default/{$smallpic}"; if(!extension_loaded('gd') || strpos($imgurl, '://')) return $imgurl; if(!file_exists($imgurl)) return "templates/default/{$smallpic}"; list($width_t, $height_t, $type, $attr) = getimagesize($imgurl); if($width == $width_t && $height == $height_t) return $imgurl; $newimgurl = "attachments/{$site_id}/thumb/" . substr(md5(dirname($imgurl) . "{$width}_{$height}"), 0, 8) . '_' . basename($imgurl); if(file_exists($newimgurl)) { return $newimgurl; } if (!file_exists("{$upload_path}/thumb")) { mkdir("{$upload_path}/thumb"); } $image = PhpThumbFactory::create($imgurl); $image->adaptiveResize($width, $height); $image->save($newimgurl); return $newimgurl; } function watermark($source, $target = '',$siteid) { global $image_w; if(empty($source)) return $source; if(!extension_loaded('gd') || strpos($source, '://')) return $source; if(!$target) $target = $source; if(!is_object($image_w)){ $image_w = new image(0); } $image_w->watermark($source, $target); return $target; } function img_write_text($imgfile, $string = '', $size = 11, $x = 0, $y =0, $color = 'red', $fontfile = "tool/font/simhei.ttf", $angle = 0) { if (!file_exists($imgfile))return false; $imginfo = getimagesize($imgfile); $s_width = $imginfo[0]; $s_height = $imginfo[1]; if (!in_array($imginfo['mime'], array("image/gif", "image/jpeg", "image/png")))return false; $string = @iconv("GB2312", 'UTF-8', $string); if ($imginfo['mime'] == 'image/gif') { $image = imagecreatefromgif($imgfile); $color = imagecolorallocate($image, rand(1, 133), rand(99, 255), rand(66, 199)); imagettftext($image, $size, $angle, $x, $y, $color, $fontfile, $string); imagegif($image, $imgfile, 100); } if ($imginfo['mime'] == 'image/jpeg') { $image = imagecreatefromjpeg($imgfile); $color = imagecolorallocate($image, rand(1, 133), rand(99, 255), rand(66, 199)); imagettftext($image, $size, $angle, $x, $y, $color, $fontfile, $string); imagegif($image, $imgfile, 100);; } if ($imginfo['mime'] == 'image/png') { $image = imagecreatefrompng($imgfile); $color = imagecolorallocate($image, rand(1, 133), rand(99, 255), rand(66, 199)); imagettftext($image, $size, $angle, $x, $y, $color, $fontfile, $string); imagegif($image, $imgfile, 100); } imagedestroy($image); } function go_url($URL, $msg = null, $window = "this"){ echo '<Script Language="JavaScript">'; if ($msg != null) { echo 'alert("' . $msg . '");'; } if ($window == 'top') { echo $window . '.window.location.reload();'; } else { echo $window . '.window.location="' . $URL . '";'; } echo '</Script>'; exit(); } function authcode($string, $operation = 'DECODE', $key = '', $expiry = 0) { $ckey_length = 4; $key = md5($key ? $key : 'siteteam'); $keya = md5(substr($key, 0, 16)); $keyb = md5(substr($key, 16, 16)); $keyc = $ckey_length ? ($operation == 'DECODE' ? substr($string, 0, $ckey_length): substr(md5(microtime()), -$ckey_length)) : ''; $cryptkey = $keya.md5($keya.$keyc); $key_length = strlen($cryptkey); $string = $operation == 'DECODE' ? base64_decode(substr($string, $ckey_length)) : sprintf('%010d', $expiry ? $expiry + time() : 0).substr(md5($string.$keyb), 0, 16).$string; $string_length = strlen($string); $result = ''; $box = range(0, 255); $rndkey = array(); for($i = 0; $i <= 255; $i++) { $rndkey[$i] = ord($cryptkey[$i % $key_length]); } for($j = $i = 0; $i < 256; $i++) { $j = ($j + $box[$i] + $rndkey[$i]) % 256; $tmp = $box[$i]; $box[$i] = $box[$j]; $box[$j] = $tmp; } for($a = $j = $i = 0; $i < $string_length; $i++) { $a = ($a + 1) % 256; $j = ($j + $box[$a]) % 256; $tmp = $box[$a]; $box[$a] = $box[$j]; $box[$j] = $tmp; $result .= chr(ord($string[$i]) ^ ($box[($box[$a] + $box[$j]) % 256])); } if($operation == 'DECODE') { if((substr($result, 0, 10) == 0 || substr($result, 0, 10) - time() > 0) && substr($result, 10, 16) == substr(md5(substr($result, 26).$keyb), 0, 16)) { return substr($result, 26); } else { return ''; } } else { return $keyc.str_replace('=', '', base64_encode($result)); } } function passport_decrypt($txt, $key) { $txt = passport_key(base64_decode($txt), $key); $tmp = ''; for ($i = 0; $i < strlen($txt); $i++) { $tmp .= $txt[$i] ^ $txt[++$i]; } return $tmp; } function passport_key($txt, $encrypt_key) { $encrypt_key = md5($encrypt_key); $ctr = 0; $tmp = ''; for($i = 0; $i < strlen($txt); $i++) { $ctr = $ctr == strlen($encrypt_key) ? 0 : $ctr; $tmp .= $txt[$i] ^ $encrypt_key[$ctr++]; } return $tmp; } function str_sub ($string, $length, $dot = ' ...', $charset = "UTF-8") { if(strlen($string) <= $length) { return $string; } $string = str_replace(array('&amp;', '&quot;', '&lt;', '&gt;'), array('&', '"', '<', '>'), $string); $strcut = ''; if(strtolower($charset) == 'utf-8') { $n = $tn = $noc = 0; while($n < strlen($string)) { $t = ord($string[$n]); if($t == 9 || $t == 10 || (32 <= $t && $t <= 126)) { $tn = 1; $n++; $noc++; } elseif(194 <= $t && $t <= 223) { $tn = 2; $n += 2; $noc += 2; } elseif(224 <= $t && $t < 239) { $tn = 3; $n += 3; $noc += 2; } elseif(240 <= $t && $t <= 247) { $tn = 4; $n += 4; $noc += 2; } elseif(248 <= $t && $t <= 251) { $tn = 5; $n += 5; $noc += 2; } elseif($t == 252 || $t == 253) { $tn = 6; $n += 6; $noc += 2; } else { $n++; } if($noc >= $length) { break; } } if($noc > $length) { $n -= $tn; } $strcut = substr($string, 0, $n); } else { for($i = 0; $i < $length; $i++) { $strcut .= ord($string[$i]) > 127 ? $string[$i].$string[++$i] : $string[$i]; } } $strcut = str_replace(array('&', '"', '<', '>'), array('&amp;', '&quot;', '&lt;', '&gt;'), $strcut); return $strcut.$dot; } function get_remote_file ($remote_file, $savefile) { if (function_exists('curl_init')) { echo '&nbsp;&nbsp;正在使用CURL进行升级...'; $GLOBALS['savefile'] = fopen($savefile, "wb"); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $remote_file); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $newfunc = create_function("\$ch, \$data", "fwrite(\$GLOBALS['savefile'], \$data); return strlen(\$data);"); curl_setopt($ch, CURLOPT_WRITEFUNCTION, $newfunc); curl_setopt($ch, CURLOPT_DNS_CACHE_TIMEOUT, 0); curl_setopt($ch, CURLOPT_TIMEOUT, 0); curl_exec($ch); curl_close($ch); fclose($GLOBALS['savefile']); } else { echo '&nbsp;&nbsp;使用fopen进行升级...'; $GLOBALS['savefile'] = fopen($savefile, "wb"); $fp = @fopen($remote_file,"r"); while(!feof($fp)) { $bytecode = fread($fp, 1024); fwrite($GLOBALS['savefile'], $bytecode, 1024); } fclose($fp); fclose($GLOBALS['savefile']); } } function post_data($url, $data, $header = '') { if (function_exists('curl_init')) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data)); curl_setopt($ch, CURLOPT_DNS_CACHE_TIMEOUT, 0); curl_setopt($ch, CURLOPT_TIMEOUT, 0); $return = curl_exec($ch); curl_close($ch); return $return; } else { $parse_url = parse_url($url); if (is_array($data)) { $post_str = array(); foreach ($data as $k => $v) { $post_str[] = "{$k}=" . ($v); } $data = implode('&', $post_str); } if ($header == '') { $header = "POST {$url} HTTP/1.1" . "\r\n"; $header .= "Accept: text/html, application/xhtml+xml, */*" . "\r\n"; $header .= "Accept-Language: zh-CN" . "\r\n"; $header .= "User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)" . "\r\n"; $header .= "Content-Type: application/x-www-form-urlencoded" . "\r\n"; $header .= "Host: {$parse_url['host']}" . "\r\n"; $header .= "Content-Length: " . strlen($data) . "\r\n"; $header .= "Connection: Keep-Alive" . "\r\n"; $header .= "Pragma: no-cache" . "\r\n"; $header .= "Connection: Close" . "\r\n"; $header .= "\r\n"; } $context = array( 'http' => array( 'method' => 'POST', 'header' => $header, 'content' => $data ), ); $stream_context = stream_context_create($context); return file_get_contents($url, False, $stream_context); } } function xsite_fsockopen($host, $port = 80, &$errno, &$errstr, $timeout) { $ip = gethostbyname($host); $s = socket_create(AF_INET, SOCK_STREAM, 0); if (socket_set_nonblock($s)) { $r = @socket_connect($s, $ip, $port); if ($r || socket_last_error() == 115) { $errno = 115; return $s; } } $errno = socket_last_error($s); $errstr = socket_strerror($errno); socket_close($s); return false; } function cat_subcategory($category, &$data) { if (is_array($data) && count($data)) { $temp = array(); foreach ($data as $k => $v) { if ($category == $v['parent_category']) { $temp[$k] = $v; } } return $temp; } else { return array(); } } function cat_category_tree_format($category = 0, &$data, $temp = array()) { $tmp = cat_subcategory($category, $data); if (is_array($tmp) && count($tmp)) { $temp = $tmp; foreach ($tmp as $k => $v) { $temp[$k]['subcategory'] = cat_category_tree_format($k, $data, $temp); } return $temp; } } function cat_tree_category($category = '', &$data) { if ($category != '') { $temp = array(); $temp[$category] = $data[$category]; $temp[$category]['subcategory']= cat_category_tree_format($category, $data); } else { $temp = cat_category_tree_format($category, $data); } return $temp; } function cat_child_category($category, &$data) { static $temp = array(); if (!empty($category)) { $temp[$category] = $data[$category]; } $sub_category = cat_subcategory($category, $data); if (is_array($sub_category) && count($sub_category)) { foreach ($sub_category as $k => $v) { cat_child_category($k, $data); } } return $temp; } function cat_parent_category($category, &$data) { static $temp; if (array_key_exists($category, $data)) { $temp[$category] = $data[$category]; if (array_key_exists($data[$category]['parent_category'], $data)) { cat_parent_category($data[$category]['parent_category'], $data); } } return $temp; } function cat_root_category($category, &$data) { if ($category != '' && array_key_exists($category, $data)) { if ($data[$category]['parent_category'] == '') { return ''; } else { $temp = cat_parent_category($category, $data); $temp = array_keys($temp); $temp = array_pop($temp); return $temp; } } else { return ''; } } function cat_plane_category($category, &$data) { $planedata = cat_child_category($category, $data); $parentdata = cat_parent_category($category, $data); $data = array_merge($parentdata, $planedata); $temp = array(); if (is_array($data) && count($data)) { foreach ($data as $k => $v) { $temp[$k] = $v; } return $temp; } else { return array(); } } function exit_msg($msg) { $msg = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>xSite建站软件提示</title></head><body>' . $msg . '</body></html>'; echo $msg; exit(); } function cat_category_url (&$system_category) { foreach ($system_category as $k => $v) { $subcatefory = cat_subcategory($k, $system_category); if ($v['module'] == 'article' || $v['module'] == 'product') { if (is_array($subcatefory) && count($subcatefory)) { $system_category[$k]['category_link'] = SITE_REWRITE ? SITE_PATH . "/{$v['main_tpl']}/{$k}.html" : SITE_PATH . "/?{$v['main_tpl']}/{$k}.html"; } else { $system_category[$k]['category_link'] = SITE_REWRITE ? SITE_PATH . "/{$v['list_tpl']}/{$k}.html" : SITE_PATH . "/?{$v['list_tpl']}/{$k}.html"; } } elseif ($v['module'] == 'page') { $system_category[$k]['category_link'] = SITE_REWRITE ? SITE_PATH . "/{$v['detailed_tpl']}/{$k}.html" : SITE_PATH . "/?{$v['detailed_tpl']}/{$k}.html"; } elseif ($v['module'] == 'link') { $system_category[$k]['category_link'] = $v['linkurl']; } } } function str_filter($text, $default_value = '') { $getfilter = "<[^>]*?=[^>]*?&#[^>]*?>|\\b(alert\\(|confirm\\(|expression\\(|prompt\\()|<[^>]*?\\b(onerror|onmousemove|onload|onclick|onmouseover)\\b[^>]*?>|^\\+\\/v(8|9)|\\b(and|or)\\b\\s*?([\\(\\)'\"\\d]+?=[\\(\\)'\"\\d]+?|[\\(\\)'\"a-zA-Z]+?=[\\(\\)'\"a-zA-Z]+?|>|<|\s+?[\\w]+?\\s+?\\bin\\b\\s*?\(|\\blike\\b\\s+?[\"'])|\\/\\*.+?\\*\\/|<\\s*script\\b|\\bEXEC\\b|UNION.+?SELECT|UPDATE.+?SET|INSERT\\s+INTO.+?VALUES|(SELECT|DELETE).+?FROM|(CREATE|ALTER|DROP|TRUNCATE)\\s+(TABLE|DATABASE)"; $postfilter = "<[^>]*?=[^>]*?&#[^>]*?>|\\b(alert\\(|confirm\\(|expression\\(|prompt\\()|<[^>]*?\\b(onerror|onmousemove|onload|onclick|onmouseover)\\b[^>]*?>|\\b(and|or)\\b\\s*?([\\(\\)'\"\\d]+?=[\\(\\)'\"\\d]+?|[\\(\\)'\"a-zA-Z]+?=[\\(\\)'\"a-zA-Z]+?|>|<|\s+?[\\w]+?\\s+?\\bin\\b\\s*?\(|\\blike\\b\\s+?[\"'])|\\/\\*.+?\\*\\/|<\\s*script\\b|\\bEXEC\\b|UNION.+?SELECT|UPDATE.+?SET|INSERT\\s+INTO.+?VALUES|(SELECT|DELETE).+?FROM|(CREATE|ALTER|DROP|TRUNCATE)\\s+(TABLE|DATABASE)"; $cookiefilter = "\\b(and|or)\\b\\s*?([\\(\\)'\"\\d]+?=[\\(\\)'\"\\d]+?|[\\(\\)'\"a-zA-Z]+?=[\\(\\)'\"a-zA-Z]+?|>|<|\s+?[\\w]+?\\s+?\\bin\\b\\s*?\(|\\blike\\b\\s+?[\"'])|\\/\\*.+?\\*\\/|<\\s*script\\b|\\bEXEC\\b|UNION.+?SELECT|UPDATE.+?SET|INSERT\\s+INTO.+?VALUES|(SELECT|DELETE).+?FROM|(CREATE|ALTER|DROP|TRUNCATE)\\s+(TABLE|DATABASE)"; if (preg_match("/".$getfilter."/is", $text)){ return $default_value; } if (preg_match("/".$postfilter."/is", $text)){ return $default_value; } if (preg_match("/".$cookiefilter."/is", $text)){ return $default_value; } return $text; } function array_json_encode( $array ){ if( !is_array( $array ) ){ return false; } if (function_exists('json_encode')) { return json_encode($array); } require_once SITE_ROOT . "/include/json.php"; $json = new Services_JSON(); return $json->encode($array); } function array_json_decode($data) { if (function_exists('json_decode')) { return json_decode($data); } require_once SITE_ROOT . "/include/json.php"; $json = new Services_JSON(); return $json->decode($data); } ?>